﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using WebComponents;
using WebComponents.Data;
using WebComponents.Security;
using GBIT.Web;
using System.IO;

public partial class ThayDoiDownload : UserControlBase {
  protected void Page_Load(object sender, EventArgs e) {
    this.Title = "Thay đổi order form";
    this.SaveTitle = "Lưu lại";
    LoadFile();
    this.SaveEnabled = true;
  }
  private void LoadFile() {
    try {
      string[] arr = File.ReadAllLines(HttpContext.Current.Server.MapPath("../App_Data/OrderForm.txt"));
      if (arr.Length >= 2) {
        hpDownload.NavigateUrl = "~/Download/" + arr[0];
        hpDownload.Text = arr[0];
        hpShirt.NavigateUrl = "~/Download/" + arr[1];
        hpShirt.Text = arr[1];

      }
    } catch { }
  }
  protected string Upload() {
    string strFileUrl = "";
    string FilePath = "../Download";
    if (fileHinh.HasFile) {

      string strFilePathLarge = HttpContext.Current.Server.MapPath(FilePath + "/" + fileHinh.FileName);

      fileHinh.SaveAs(strFilePathLarge);

      strFileUrl = "Download/" + fileHinh.FileName;
    }
    if (fileShirt.HasFile) {

      string strFilePathLarge = HttpContext.Current.Server.MapPath(FilePath + "/" + fileShirt.FileName);

      fileShirt.SaveAs(strFilePathLarge);

      strFileUrl = "Download/" + fileShirt.FileName;
    }
    return fileHinh.FileName + "\r\n" + fileShirt.FileName;
  }
  protected override void OnSaveRecord(bool redirect) {
    if (fileHinh.HasFile) {
      File.WriteAllText(HttpContext.Current.Server.MapPath("../App_Data/OrderForm.txt"), Upload());
    }
    LoadFile();
    Security.ShowClientMessage(Page, "Lưu thông tin order form thành công!");
  }

}
